'use strict';
Object.defineProperties(exports, {
  __esModule: { value: !0 },
  [Symbol.toStringTag]: { value: 'Module' },
});
require('../yaml/visit.cjs');
require('../yaml/stringify/stringifyString.cjs');
require('../yaml/parse/cst-visit.cjs');
const i = require('../yaml/public-api.cjs');
let f = '\\ufeff?',
  s = typeof process < 'u' ? process.platform : '',
  c =
    '^(' +
    f +
    '(= yaml =|---)$([\\s\\S]*?)^(?:\\2|\\.\\.\\.)\\s*$' +
    (s === 'win32' ? '\\r?' : '') +
    '(?:\\n)?)',
  u = new RegExp(c, 'm');
function p(e, t) {
  e = e || '';
  let r = {};
  t = t instanceof Object ? { ...r, ...t } : r;
  let l = e.split(/(\r?\n)/);
  return l[0] && /= yaml =|---/.test(l[0])
    ? o(e)
    : { attributes: {}, body: e, bodyBegin: 1 };
}
function d(e, t) {
  let r = 1,
    l = t.indexOf(`
`),
    n = e.index + e[0].length;
  for (; l !== -1; ) {
    if (l >= n) return r;
    r++,
      (l = t.indexOf(
        `
`,
        l + 1,
      ));
  }
  return r;
}
function o(e) {
  let t = u.exec(e);
  if (!t) return { attributes: {}, body: e, bodyBegin: 1 };
  let r = t[t.length - 1].replace(/^\s+|\s+$/g, ''),
    l = i.parse(r) || {},
    n = e.replace(t[0], ''),
    a = d(t, e);
  return { attributes: l, body: n, bodyBegin: a, frontmatter: r };
}
function b(e) {
  return (e = e || ''), u.test(e);
}
exports.default = p;
exports.parse = o;
exports.test = b;
